﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace com.dbo
{
    public class DB
    {
        public static readonly string CnStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        public static SqlConnection getCn()
        {
            return new SqlConnection(CnStr);
        }
        public static SqlCommand getCmd(string sp)
        {
            SqlCommand cmd = new SqlCommand(sp,getCn());
            return cmd;
        }
        public static SqlCommand getCmdSp(string sp)
        {
            SqlCommand cmd = new SqlCommand(sp, getCn());
            cmd.CommandType = CommandType.StoredProcedure;
            return cmd;
        }
        public static DataTable getTable(string sql)
        {
            
            SqlDataAdapter adp = new SqlDataAdapter(sql, CnStr);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            return dt;
        }
        public static object getScalar(string q)
        {
            SqlCommand cmd = new SqlCommand(q, getCn());
            cmd.Connection.Open();
            object c = cmd.ExecuteScalar();
            cmd.Connection.Close();
            return c;
        }
        

    }
}